<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="/bootstrap_datetimepicker/bootstrap-datetimepicker.css">
<script type="text/javascript" src="/bootstrap_datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="/bootstrap_switch/bootstrap_switch.js"></script>
<link rel="stylesheet" type="text/css" href="/bootstrap_switch/bootstrap_switch.css">
<style>
    .survey{height: 130px;}
    .container{width: 90%;margin-top: 20px;margin-left: 0px;}
    .col-sm-4{border: 1px solid #ddd;background-color: #fff;}
    .div-left{width: 45%;overflow-y:scroll;}
    .div-centre{width: 53.5%;margin-left: 10px;overflow-y:scroll;}
    .quick{text-align: center;height: 18%;width: 70%;margin-top: 25%;margin-left: 16%;border: 1px solid #ddd;background-color: #dddddd;font-size: 16px;border-radius: 4px;}
    .describe{border-bottom: 1px solid #ddd;}
    .describe>td{height: 33px;line-height: 33px;}
    .summary{text-align:center;margin-top: -17px;border: 1px solid #ddd;width: 20%;height: 100px;float: left;border-radius: 5px;}
    .summary-title{margin-top: 20px;}
    .summary-content{font-size: 20px;margin-top: 5px;}
    .quick-right{border: 1px solid #ddd;background-color: #fff;float:right ;margin-top: 20px;width: 9%;}
    .quick-tool{text-align: center;width: 70%;margin-top: 25%;margin-left: 16%;font-size: 18px;font-weight: 800;}

    .modal-body .form-group>label{float:left;padding-top: 8px;width: 100px;}
    #numerical>input{width: 20%;float:left;margin-left: -12px;border-radius: 4px;}
    .weeks{font-weight: 500;margin-top: 9.3px;vertical-align:middle;margin-left: 13px;}
    .video-box{
        position: absolute;
        top: 30px;
        right: 0px;
        width: 30%;
        height: 70%;
    }
</style>
<body>
@if(isset($_error)&&!empty($_error))
    <div class="alert alert-danger" role="alert">{{$_error}}</div>
@endif
    <div class="survey" style="border: 1px solid #ddd;background-color: #fff;">
    <div style="font-size: 16px;margin: 10px 0 0 10px;"><b>今日概况</b></div>
    <div class="summary" style="margin-left:10%;">
        <div class="summary-title">累计咨询人数</div>
        <div class="summary-content"><b id="consulting"></b></div>
    </div>
    <div class="summary" style="margin-left:5%;">
        <div class="summary-title">已处理</div>
        <div class="summary-content"><b id="resolved"></b></div>
    </div>
    <div class="summary" style="margin-left:5%;">
        <div class="summary-title">未处理</div>
        <div class="summary-content" style="color: red;"><b id="notsolved"></b></div>
    </div>
</div>
<div class="container" style="float: left;">
    <div class="row">
        <div class="col-sm-4 div-left">
            <table style="width: 100%;">
                <tbody id="graphic">
                    <tr class="describe">
                        <th style="height: 40px;line-height: 40px;">图文问诊</th>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="col-sm-4 div-centre">
            <div style="margin: 10px 0 0 10px;"><b>图文详情</b><button type="button" style="margin-left: 77%;height: 25px;line-height: 2px;" data_id="0" class="btn btn-info btn_reply">回复</button></div>
            <div style="margin-left: 15px;" id="content">

            </div>
        </div>
    </div>
</div>
<div class="quick-right">
    <div class="quick-tool">快捷工具</div>
    <button class="quick service">服务设置</button>
    <button class="quick">处方审核</button>
    <button class="quick">个人资料</button>
</div>
<div class="container" style="float: left;">
    <div class="row">
        <div class="col-sm-4 div-left">
            <table style="width: 100%;">
                <tr class="describe">
                    <th style="height: 40px;line-height: 40px;">视频问诊</th>
                </tr>
                @if(isset($video_call_info['camera_user_info']->nickname) && !empty($video_call_info['camera_user_info']->nickname))
                    <tr id="call_item" class="describe">
                        <td id="temp_call" item_trade_no="{{$video_call_info['trade_no']}}"><span class="label label-info">临时</span> 用户名 {{$video_call_info['camera_user_info']->nickname}} <span id="call_state">视频通话中。。。</span></td>
                    </tr>
                @endif
            </table>
        </div>
        <div class="col-sm-4 div-centre">
            <div style="margin: 10px 0 0 10px;"><b>视频窗口</b></div>
            @if($video_call==1)
            <div class="col-div" style="display:none;width: 320px">
                <div class="form-group bmd-form-group is-filled" style="width: 100%; height: 80px">
                    <label for="userId" class="bmd-label-floating">用户名:</label>
                    <input type="text" class="form-control" @if(isset($video_call_info)) value="{{$video_call_info['doc_uid']}}" @endif name="userId" id="userId" maxlength="18">
                </div>
                <div class="form-group bmd-form-group is-filled" style="width: 100%; height: 80px">
                    <label for="roomId" class="bmd-label-floating">房间号:</label>
                    <input type="text" class="form-control" @if(isset($video_call_info)) value="{{$video_call_info['room']}}" @endif name="roomId" id="roomId" maxlength="18">
                </div>
                <div style="height: 24px"></div>
                <!-- 登录 -->

                <!-- 摄像头 麦克风 -->
                <div class="row-div" style="width: 100%; height: 105px; justify-content: center">
                    <img id="camera" style="height: 27px" src="/tencent_im/img/camera.png" onClick="event.cancelBubble = true"
                         data-toggle="popover" data-placement="top" title="" data-content="">
                    <!-- 选择摄像头 -->
                    <div id="camera-option" style="display: none"></div>
                    <div style="width: 100px"></div>
                    <img id="microphone" style="height: 27px" src="/tencent_im/img/mic.png"
                         onClick="event.cancelBubble = true" data-toggle="popover" data-placement="top" title=""
                         data-content="">
                    <div style="width: 100px"></div>

                    <!-- 选择麦克风 -->
                    <div id="mic-option" style="display: none"></div>
                </div>
                <!-- 设备检测按钮 -->
                <div id="device-testing-btn" class="device-testing-btn">
                    <div class="device-icon">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-shebei"></use>
                        </svg>
                    </div>
                    设备检测
                </div>
                <div id="device-connect-list" class="device-connect-list" style="display: none;">
                    <div id="connect-camera" class="connect icon-normal">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-shiping-xue"></use>
                        </svg>
                    </div>
                    <div id="connect-voice"  class="connect icon-normal">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-shengyin"></use>
                        </svg>
                    </div>
                    <div id="connect-mic" class="connect icon-normal">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-maikefeng-xue"></use>
                        </svg>
                    </div>
                    <div id="connect-network" class="connect icon-normal">
                        <svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-wangluo"></use>
                        </svg>
                    </div>
                </div>
            </div>
            <div style="width: 100%;height: 100%;">
                <div id="video-grid" style="height: 100%; flex: 1">
                    <!-- 主视频 -->
                    <div id="main-video" class="video-box col-div" style="justify-content: flex-end;width:100%;height:100%;">
                        <!-- 主视频控制按钮 -->
                        <div id="main-video-btns" class="row-div"
                             style="width: 234px; position: absolute; z-index: 10; justify-content: center; align-self: flex-end">
                            <img id="video-btn" style="width: 68px; height: 68px" onClick="event.cancelBubble = true"
                                 src="/tencent_im/img/big-camera-on.png" alt="" title="关闭摄像头">
                            <img id="mic-btn" style="width: 68px; height: 68px" onClick="event.cancelBubble = true"
                                 src="/tencent_im/img/big-mic-on.png" alt="" title="关闭麦克风">
                             <img id="logout-btn" style="width: 68px; height: 68px" onClick="event.cancelBubble = true"
                                 src="/tencent_im/img/logout.png" alt="" title="结束通话">

                        </div>
                        <div id="mask_main" class="mask col-div">
                            <!-- “摄像头未开启”遮罩 -->
                            <div style="height: 100%; width: 100%; position: absolute; background-color: #D8D8D8"></div>
                            <img style="width: 63px; height: 69px; z-index: 10;" src="/tencent_im/img/camera-max.png" alt="">
                            <div style="height: 10px"></div>
                            <div style="z-index: 10">摄像头未打开</div>
                        </div>
                    </div>
                    <!-- 小视频 -->
                    {{--<button id="login-btn" type="button" class="btn btn-raised btn-primary"
                            style="width: 100%; height: 40px">进入房间
                        <div class="ripple-container"></div>
                    </button>--}}
                </div>
            </div>
            @endif
        </div>
    </div>
</div>

{{--服务设置--}}
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="border-radius: 10px;margin-top:30%;">
            <div class="modal-header" style="background: #3c8dbc;color: #fff;border-top-left-radius:10px;border-top-right-radius: 10px;">
                <h4 class="modal-title" id="myModalLabel">新增</h4>
            </div>
            <div class="modal-body">
                <div class="form-group" style="border-bottom: 1px solid #f4f4f4;">
                    <div class="switch" style="margin-top: 5px;">
                        <b style="font-size: 16px;vertical-align: middle;margin-right: 20px;">咨询设置</b>
                        <input style="vertical-align: middle;" type="checkbox"/>
                    </div>
                    <div id="service-time" style="margin-top: 20px;margin-bottom: 27px;">
                        <span>服务时间段：</span>
                        <label style="font-weight: 500;margin-left: 10px;">开始：</label>
                        <input type="text" style="border:1px solid #ddd;border-radius: 4px;height: 30px;" name="start_time" autocomplete="off" id="start_time">
                        <label style="font-weight: 500;margin-left: 30px;">结束：</label>
                        <input type="text" style="border:1px solid #ddd;border-radius: 4px;height: 30px;" name="end_time" autocomplete="off" id="end_time">
                    </div>
                </div>
                <div id="weeks-plan">
                    <div style="margin-top: 22px;">重复计划：</div>
                    <div style="margin-top: 7px;">
                        <input type="checkbox" id="weeks-type-0" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">每天</label>
                        <input type="checkbox" id="weeks-type-1" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周一</label>
                        <input type="checkbox" id="weeks-type-2" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周二</label>
                        <input type="checkbox" id="weeks-type-3" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周三</label>
                    </div>
                    <div style="margin-top: 7px;">
                        <input type="checkbox" id="weeks-type-4" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周四</label>
                        <input type="checkbox" id="weeks-type-5" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周五</label>
                        <input type="checkbox" id="weeks-type-6" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周六</label>
                        <input type="checkbox" id="weeks-type-7" style="margin-left: 50px;vertical-align:middle;display:inline-block;"><label class="weeks">周日</label>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"  style="margin-left: 20px;">确 定</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="myModal-1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel-1">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="border-radius: 10px;margin-top:30%;">
            <div class="modal-header" style="background: #3c8dbc;color: #fff;border-top-left-radius:10px;border-top-right-radius: 10px;">
                <h4 class="modal-title" id="myModalLabel-1">新增</h4>
            </div>
            <div class="modal-body">
                <textarea rows="8" style="width: 100%;" id="reply_content" class="form-control"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" id="btn_submit" class="btn btn-primary sub_reply" data-dismiss="modal"  style="margin-left: 20px;">确 定</button>
            </div>
        </div>
    </div>
</div>
</body>
{{--<link rel="stylesheet" href="/tencent_im/css/bootstrap-material-design.min.css">
<link rel="stylesheet" href="/tencent_im/css/index.css">
<link rel="stylesheet" href="/tencent_im/css/room.css">--}}
@if($video_call==1)
<script src="/tencent_im/js/popper.js"></script>
<script src="/tencent_im/js/bootstrap-material-design.js"></script>
<script src="/tencent_im/js/lib-generate-test-usersig.min.js"></script>

<script src="/tencent_im/js/iconfont.js"></script>
<script src="/tencent_im/js/trtc.js"></script>
<script src="/tencent_im/js/common4.js"></script>
<script src="/tencent_im/js/rtc-client2.js"></script>
<script src="/tencent_im/js/share-client.js"></script>
<script src="/tencent_im/js/presetting.js"></script>
<script src="/tencent_im/js/device-testing.js"></script>
<script src="/tencent_im/js/index.js"></script>
@endif
<script>

    //视频逻辑 start
    @if($video_call==1)
        $(function () {
            var is_connected=0;
            var room = {!! $video_call_info['room'] !!};
            var user_nickname = "{!! $video_call_info['camera_user_info']->nickname !!}";
            var doctor_sid = "{!! $video_call_info['doctor_admin_sid'] !!}";
            var doctor_sign = "{!! $video_call_info['sign'] !!}";
            var trade_no = "{!! $video_call_info['trade_no'] !!}";
            $('#roomId').val(room)
            var config = {
                sdkAppId: "{!! $video_call_info['userSignConfig']['sdkAppid'] !!}",
                userSig: "{!! $video_call_info['userSignConfig']['userSgin'] !!}",
                doctor_sid:doctor_sid,
                doctor_sign:doctor_sign,
                trade_no:trade_no,
                room:room
            }
            login(config)
            //console.log($('.video-box').length)

        })
    @endif
    //视频通话逻辑 end
    var windowHeight = window.innerHeight;
    var height = windowHeight / 2 - 180;
    $('.div-left').css('height',height);
    $('.div-centre').css('height',height);
    $('.quick-right').css('height',windowHeight-340);
    $('.quick').css('line-height',$('.quick').height()+'px');

    //服务设置
    $('.switch input').bootstrapSwitch({
        "onColor" : "success",
        "offColor" : "danger",
        "onText" : "启用",
        "offText" : "禁用",
        // "size" : "small",
        onSwitchChange:function(event,state){
            if(state==true){
                $('#service-time').show();
                $('#weeks-plan').show();
                $('#btn_submit').attr('is_consulting','1');
            }else{
                $('#service-time').hide();
                $('#weeks-plan').hide();
                $('#btn_submit').attr('is_consulting','0');
            }
        }
    });
    //获取数据
    $('.service').click(function () {
        var index = layer.load(0, {shade: '#ccc'});
        //获取到数据
        $.ajax({
            url : "{{admin_url('doctor/consulting/get_consulting_time')}}",
            type:'post',
            dataType:'json',
            async:false,
            data:{},
            success:function(result){
                layer.close(index);
                console.log(result);
                if ( result.code != 0 ) {
                    layer.msg('获取失败');
                }else{
                    var data = result.data.list;
                    if ( data && data.length > 0 ) {
                        $('#start_time').val(data.start_time);
                        $('#end_time').val(data.end_time);
                        var weeks_type = data.weeks_type.split(",");
                        for ( var i=0;i<weeks_type.length;i++ ) {
                            if ( weeks_type[i] == '-1' ) {
                                $('#weeks-type-0').attr('checked','checked');
                            }else if( weeks_type[i] == '1' ) {
                                $('#weeks-type-1').attr('checked','checked');
                            }else if( weeks_type[i] == '2' ) {
                                $('#weeks-type-2').attr('checked','checked');
                            }else if( weeks_type[i] == '3' ) {
                                $('#weeks-type-3').attr('checked','checked');
                            }else if( weeks_type[i] == '4' ) {
                                $('#weeks-type-4').attr('checked','checked');
                            }else if( weeks_type[i] == '5' ) {
                                $('#weeks-type-5').attr('checked','checked');
                            }else if( weeks_type[i] == '6' ) {
                                $('#weeks-type-6').attr('checked','checked');
                            }else if( weeks_type[i] == '0' ) {
                                $('#weeks-type-7').attr('checked','checked');
                            }
                        }
                    }
                    if ( result.data.is_consulting == 1 ) {
                        // $('.switch input').attr('checked','checked');
                        $('.switch input').bootstrapSwitch('state',true);
                        $('#btn_submit').attr('is_consulting','1');
                    }else{
                        $('.switch input').bootstrapSwitch('state',false);
                        $('#service-time').hide();
                        $('#weeks-plan').hide();
                        $('#btn_submit').attr('is_consulting','0');
                    }
                    $('#btn_submit').attr('doctor_id',result.data.doctor_id);
                }
            }
        });
        $("#myModalLabel").text("咨询时间设置");
        $('#myModal').modal();
    });
    //提交数据
    $('#btn_submit').click(function () {
        var index = layer.load(0, {shade: '#ccc'});
        var is_consulting = $(this).attr('is_consulting');
        var doctor_id = $(this).attr('doctor_id');
        var start_time = $('#start_time').val();
        var end_time = $('#end_time').val();
        var weeks_type_0 = $('#weeks-type-0').prop("checked");
        var weeks_type_1 = $('#weeks-type-1').prop("checked");
        var weeks_type_2 = $('#weeks-type-2').prop("checked");
        var weeks_type_3 = $('#weeks-type-3').prop("checked");
        var weeks_type_4 = $('#weeks-type-4').prop("checked");
        var weeks_type_5 = $('#weeks-type-5').prop("checked");
        var weeks_type_6 = $('#weeks-type-6').prop("checked");
        var weeks_type_7 = $('#weeks-type-7').prop("checked");
        var weeks_str = '';
        if ( weeks_type_0 ) {
            weeks_str += '-1,';
        }
        if ( weeks_type_1 ) {
            weeks_str += '1,';
        }
        if ( weeks_type_2 ) {
            weeks_str += '2,';
        }
        if ( weeks_type_3 ) {
            weeks_str += '3,';
        }
        if ( weeks_type_4 ) {
            weeks_str += '4,';
        }
        if ( weeks_type_5 ) {
            weeks_str += '5,';
        }
        if ( weeks_type_6 ) {
            weeks_str += '6,';
        }
        if ( weeks_type_7 ) {
            weeks_str += '0,';
        }
        var weeks_str = weeks_str.substring(0,weeks_str.length-1);
        $.ajax({
            url : "{{admin_url('doctor/consulting/set_consulting_time')}}",
            type:'post',
            dataType:'json',
            data:{'is_consulting':is_consulting,'start_time':start_time,'end_time':end_time,'weeks_type':weeks_str,'doctor_id':doctor_id},
            success:function(result){
                layer.close(index);
                if ( result.code != 0 ) {
                    layer.msg('添加失败')
                }else{
                    $('#myModal').hide();
                }
            }
        });
        console.log(weeks_str);
    });


    //初始化时间插件
    $("#start_time").datetimepicker({
        minView : "hour", //  选择时间时，最小可以选择到那层；默认是‘hour’也可用0表示
        startView:'day',
        language : 'zh-CN', // 语言
        autoclose : true, //  true:选择时间后窗口自动关闭
        format : 'hh:ii', // 文本框时间格式，设置为0,最后时间格式为2017-03-23 17:00:00
        // todayBtn : true, // 如果此值为true 或 "linked"，则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。
        minuteStep:5,       //一分钟展示形式
    });
    $("#end_time").datetimepicker({
        minView : "hour", //  选择时间时，最小可以选择到那层；默认是‘hour’也可用0表示
        startView:'day',
        language : 'zh-CN', // 语言
        autoclose : true, //  true:选择时间后窗口自动关闭
        format : 'hh:ii', // 文本框时间格式，设置为0,最后时间格式为2017-03-23 17:00:00
        // todayBtn : true, // 如果此值为true 或 "linked"，则在日期时间选择器组件的底部显示一个 "Today" 按钮用以选择当前日期。
        minuteStep:5,       //一分钟展示形式
    })

    /**
     * 获取图文咨询列表
     */
    getList();
    function getList(){
        $('.btn_reply').attr('data_id','0');
        $.ajax({
            url : "{{admin_url('doctor/get_diagnose_list')}}",
            type:'post',
            dataType:'json',
            data:{},
            success:function(result){
                if ( result.code != 0 ) {
                    layer.msg('图文问诊列表获取失败');
                }else{
                    var date = new Date();
                    var dateStr = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' '+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds();
                    var data = result.data;
                    var html = '<tr class="describe"><th style="height: 40px;line-height: 40px;">图文问诊</th><th></th><th></th></tr>';
                    for ( var i = 0; i<data.length; i++ ) {
                        html += '<tr class="describe list-tr" data_id="'+data[i].id+'">';
                        if ( data[i].status == 3 ) {
                            html +=     '<td style="width:60px;"><button style="pointer-events:none;border:0;border-radius: 4px;background:#777777;color:#FFFFFF;line-height: 2px;height: 20px;">追加</button></td>';
                        }else{
                            html +=     '<td style="width:60px;"></td>';
                        }
                        if ( data[i].content.length > 20 ) {
                            data[i].content =  data[i].content.substring(0,19)+'....';
                        }
                        html +=     '<td>'+data[i].content+'</td>';
                        //等到时长
                        var re=getHoursDiff(data[i].updated_at,dateStr);
                        var h=parseInt(re);
                        var m=parseInt((re-h)*60);
                        var waitingTime = h > 0 ? "等待时长"+h+"小时"+m+"分钟" : "等待时长"+m+"分钟";
                        html +=     '<td style="color:red;width: 150px;">'+waitingTime+'</td>';
                        html += '</tr>';
                    }
                    $("#graphic").html(html);
                    console.log(html);
                }

            }
        });
    }

    statistics();
    //获取统计数据
    function statistics(){
        $.ajax({
            url : "{{admin_url('doctor/statistics')}}",
            type:'post',
            dataType:'json',
            data:{},
            success:function(result){
                console.log(result);
                if ( result.code != 0 ) {
                    layer.msg('统计数据获取失败');
                }else{
                    $('#consulting').html(result.data.consulting+' 人 次');
                    $('#notsolved').html(result.data.notsolved+' 人 次');
                    $('#resolved').html(result.data.resolved+' 人 次');
                }
            }
        });
    }

    //获取图文咨询详情
    $(document).on('click','.list-tr',function () {
        var data_id = $(this).attr('data_id');
        $('.list-tr').attr('style','background-color:ffffff;color:#333;');
        $(this).attr('style','background-color:#00CCCC;color:#fff;');
        $.ajax({
            url : "{{admin_url('doctor/get_diagnose')}}",
            type:'post',
            dataType:'json',
            data:{'id':data_id},
            success:function(result){
                console.log(result);
                if ( result.code != 0 ) {
                    layer.msg('数据获取失败');
                }else{
                    var data = result.data.list;
                    var html = '';
                    for ( var i=0;i<data.length;i++ ) {
                        html+='<div style="margin-top: 10px;padding-bottom: 10px;border-bottom: 1px solid #ddd;line-height:25px;">';
                        if ( i == 0 ) {
                            $('.btn_reply').attr('data_id',data[0].id);
                            html+='<div><b>患者提问：<\/b><\/div>';
                        }else if( i != 0 && data[i].initiator_identity == 2 && data[i-1].initiator_identity == 2 ){
                            html+='<div><b>追加提问：<\/b><\/div>';
                        }
                        html += '<div style="margin-left: 15px;">';
                        var userdefaultImg = 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2395693894,1549853405&fm=26&gp=0.jpg';
                        var doctorfaultImg = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1601033849996&di=4719fd72b37cfabcb1ce1504de811841&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F7274e8be5b2c7f7ac56ecb34c2e45181c167ecb6d44a-feXDfj_fw658';
                        var photo = '';
                        if ( data[i].initiator_identity == 1 ) {
                            if ( data[i].photo == '' || data[i].photo == null || !data[i].photo ) {
                                photo = doctorfaultImg;
                            }else{
                                // photo = result.data.domain+data[i].photo;
                                if ( data[i].photo.indexOf("http") == -1 ) {
                                    photo = result.data.app_domain+data[i].photo;
                                } else{
                                    photo = data[i].photo;
                                }
                            }
                        }else{
                            if ( data[i].avatar == '' || data[i].avatar == null || !data[i].avatar ) {
                                photo = userdefaultImg;
                            }else{
                                if ( data[i].avatar.indexOf("http") == -1 ) {
                                    photo = result.data.domain+data[i].avatar;
                                } else{
                                    photo = data[i].avatar;
                                }
                            }
                        }
                        html += '<img src="'+photo+'" style="height: 24px;float: left;">';
                        html += '<div style="margin-left: 30px;">';
                        html += data[i].content;
                        html += '<br/>';
                        //图片
                        if ( data[i].accessory != '' && data[i].accessory != null ) {
                            var imgArr = data[i].accessory.split(',');
                            for ( var x = 0;x<imgArr.length;x++ ) {
                                html += '<img src="'+result.data.domain+imgArr[x]+'" style="height: 130px;">';
                            }
                        }
                        html += '<\/div>';
                        html += '<\/div>';
                        html += '<\/div>';
                    }
                    $('#content').html(html);
                }
            }
        });
    });

    //回复
    $('.btn_reply').click(function () {
        var data_id = $(this).attr('data_id');
        if ( data_id == 0 || !data_id ) {
            layer.msg('请选择要回复的内容');return;
        }
        $("#myModalLabel-1").text("医生回复");
        $('#myModal-1').modal();
    });

    $('.sub_reply').click(function () {
        var data_id = $('.btn_reply').attr('data_id');
        var content = $('#reply_content').val();
        if ( !content ) {
            layer.msg('回复内容不能为空');return;
        }
        var index = layer.load(0, {shade: '#ccc'});
        $.ajax({
            url : "{{admin_url('doctor/reply_diagnose')}}",
            type:'post',
            dataType:'json',
            data:{'id':data_id,'content':content},
            success:function(result){
                layer.close(index);
                if ( result.code != 0 ) {
                    layer.msg('服务端异常');return;
                }
                getList();              //列表数据
                statistics();           //统计数据
                $('#content').html('');
            }
        });
    });

    //计算两个时间相差的小时跟分钟
    function getHoursDiff(dt1,dt2) {
        if(typeof(dt1)=="string") {
            dt1=new Date(dt1.replace(/-/,'/'));
            dt2=new Date(dt2.replace(/-/,'/'));
        }
        var res=dt2-dt1;
        if(isNaN(res))
            throw Error("invalid dates arguments");
        return res/(1000*60*60);
    }
</script>